/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.stefanini.informacion_mundialista.ejbs;

import com.stefanini.informacion_mundialista.Usuario;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author CarlosAlberto
 */
@LocalBean
@Stateless
public class UserManager {
    @PersistenceContext
    private EntityManager em;
    
    public Usuario VerificarLogin(String usuario, String password){
        try{
            StringBuilder query = new StringBuilder();
            query.append("SELECT u FROM Usuario u ");
            query.append("WHERE u.username = :USERNAME");
            query.append(" AND u.password = :PASSWORD");
            
            Query q = em.createQuery(query.toString(),Usuario.class);
            q.setParameter("USERNAME", usuario);
            q.setParameter("PASSWORD", password);
        
            return (Usuario)q.getSingleResult();

        }catch(Exception e){
            Logger.getLogger(UserManager.class.getName()).log(Level.SEVERE,
                    "Error al verificar el login", e);
            return null;
        }

    }
}
